package com.hyk.learning.loadbalance;

import com.hyk.learning.common.utils.CollectionUtil;
import com.hyk.learning.dto.RpcRequest;

import java.util.List;

/**
 * @className: AbstractLoadBalance
 * @author: hyk199710
 * @description: TODO
 * @date: 2024/4/29 22:59
 */
public abstract class AbstractLoadBalance implements LoadBalance {
    @Override
    public String selectServiceAddress(List<String> serviceUrlList, RpcRequest rpcRequest) {

        if (CollectionUtil.isEmpty(serviceUrlList)) {
            return null;
        }
        if (serviceUrlList.size() == 1) {
            return serviceUrlList.get(0);
        }

        return doSelect(serviceUrlList, rpcRequest);
    }

    protected abstract String doSelect(List<String> serviceUrlList, RpcRequest rpcRequest);
}
